<template>
	<view class="mainpadding beijingse">
		<view class="sanshier nofonweight xiaohei">上传身份证</view>
		<view class="ffffff mainpadding radius margin_top" @click="uploadImg(1)">
			<view class="shenfz">
				<image v-if="!idcard_zimage" src="../../static/image/sysem/sfzzm.png" mode=""></image>
				<image v-if="idcard_zimage" :src="idcard_zimage_text" mode=""></image>
			</view>
			<view v-if="!idcard_zimage" class="huisetext1 textcenter margin_top">点击上传身份证人像面</view>
		</view>
		<view class="ffffff mainpadding radius margin_top" @click="uploadImg(2)">
			<view class="shenfz">
				<image v-if="!idcard_fimage" src="../../static/image/sysem/fanm.png" mode=""></image>
				<image v-if="idcard_fimage" :src="idcard_fimage_text" mode=""></image>
			</view>
			<view v-if="!idcard_fimage" class="huisetext1 textcenter margin_top">点击上传身份证国徽面</view>
		</view>
		<view class="ffffff mainpadding radius margin_top">
			<view class="flexleft">
				<view class="sanshier nofonweight xiaohei margin_right2" style="min-width: 160rpx;">姓名：</view>
				<input type="text" placeholder="请输入姓名" v-model="realname">
			</view>
			<view class="flexleft margin_top">
				<view class="sanshier nofonweight xiaohei margin_right2" style="min-width: 160rpx;">联系方式：</view>
				<input type="number" placeholder="请输入联系方式" v-model="mobile">
			</view>
			<view class="flexleft margin_top">
				<view class="sanshier nofonweight xiaohei margin_right2" style="min-width: 160rpx;">所在城市：</view>
				<input type="text" placeholder="请输入城市" v-model="address">
			</view>
			<view class="margin_top">
				<view class="sanshier nofonweight xiaohei margin_right2">个人简介：</view>
				<textarea class="textarea" placeholder="简单介绍一下自己吧~" v-model="des"></textarea>
			</view>
		</view>
		<view class="bigbtn margin_top" @click="submit()">确认</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				realname:"",
				mobile:"",
				address:"",
				des:"",
				idcard_zimage:"",
				idcard_zimage_text:"",
				idcard_fimage:"",
				idcard_fimage_text:"",
			}
		},
		methods: {
			submit() {
				uni.showLoading({
					title: '请稍候...',
					mask: true
				})
				if (this.realname == "") {
					uni.hideLoading()
					httpRequest.toast("请输入真实姓名")
					return
				}
				if (this.mobile == "") {
					uni.hideLoading()
					httpRequest.toast("请输入联系方式")
					return
				}
				if (this.address == "") {
					uni.hideLoading()
					httpRequest.toast("请选择所在城市")
					return
				}
				if (this.idcard_zimage == "") {
					uni.hideLoading()
					httpRequest.toast("请上传身份证正面照片")
					return
				}
				if (this.idcard_fimage == "") {
					uni.hideLoading()
					httpRequest.toast("请上传身份证反面照片")
					return
				}
				httpRequest.request('/api/user/smrz', 'GET', {
					// 传参
					realname: this.realname, //真实姓名
					mobile: this.mobile, //身份证号
					idcard_zimage:this.idcard_zimage,
					idcard_fimage:this.idcard_fimage,
					address:this.address,
					des:this.des,
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
					}
				}).catch(err => {
					uni.hideLoading()
					httpRequest.toast(err.msg);
				})
			},
			uploadImg(val) {
				let _this = this;
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
			
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(1, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], val)
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(1, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], val)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			// 详情转载
			uploadImageService(url, val) {
				let _this = this;
				httpRequest.uploadFile('/api/Common/upload', url).then(res => {
					let image_item = res.fullurl;
					if (val == 1) {
						this.idcard_zimage = res.url
						this.idcard_zimage_text = image_item
					}
					if (val == 2) {
						this.idcard_fimage = res.url
						this.idcard_fimage_text = image_item
					}
				}).catch(err => {});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.textarea {
		margin-top: 30rpx;
		padding: 20rpx;
		background: #F5F5F5;
		width: 100%;
		box-sizing: border-box;
		border-radius: 10rpx;
	}

	.shenfz {
		width: 407rpx;
		height: 197rpx;
		margin: auto;

		image {
			width: 100%;
			height: 100%;
		}
	}
</style>